﻿app.controller('AppCtrl', function ($scope,$http, $ionicModal, $ionicPopover, $timeout, ionicMaterialInk, $localstorage) {
    // Form data for the login modal
    $scope.loginData = {};

    var navIcons = document.getElementsByClassName('ion-navicon');
    for (var i = 0; i < navIcons.length; i++) {
        navIcons.addEventListener('click', function () {
            this.classList.toggle('active');
        });
    }
    var fab = document.getElementById('fab');
    $scope.motionFab = function (type) {
        var shouldAnimate = false;
        var classes = type instanceof Array ? type : [type];
        for (var i = 0; i < classes.length; i++) {
            fab.classList.toggle(classes[i]);
            shouldAnimate = fab.classList.contains(classes[i]);
            if (shouldAnimate) {
                (function (theClass) {
                    $timeout(function () {
                        fab.classList.toggle(theClass);
                    }, 300);
                })(classes[i]);
            }
        }
    };
    ionicMaterialInk.displayEffect();

    //购物车框框
    var template_cart = '<ion-popover-view class="cart-popover" style="margin-top: -12px;">' +
        '   <ion-header-bar>' +
        '       <h1 class="title">购物车</h1>' +
        '   </ion-header-bar>' +
        '   <ion-content class="padding">' +
        '       My Popover Contents' +
        '   </ion-content>' +
        '</ion-popover-view>';

    $scope.popover = $ionicPopover.fromTemplate(template_cart, {
        scope: $scope
    });
    $scope.cartPopoverShow = function ($event) {
        $scope.motionFab('drop');
        $scope.popover.show($event);
    }
    $scope.closePopover = function () {
        $scope.popover.hide();
    };
    $scope.$on('$destroy', function () {
        $scope.popover.remove();
    });

    $scope.activeMenuTitle = 'home';
    $scope.changeMenu = function (v) {
        $scope.activeMenuTitle = v;
    };

    //微信个人信息
    $scope.nickname = $localstorage.getObject('weiInfo').nickname;
    $scope.faceimg = $localstorage.getObject('weiInfo').headimgurl;

});